package example.neon;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

import static util.Util.getRealFile;

public class JPanelCollapseHead extends JPanel {
    //    Color backgroundColor = new Color(14, 14, 14);
    String title;
    BufferedImage icon;

    public JPanelCollapseHead(String title) {
        try {
            icon = ImageIO.read(getRealFile("img/neon/down.png"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        this.title = title;
        this.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
    }

    public void iconRotate(double angle) {
        BufferedImage rotate = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
        Graphics2D graphics = rotate.createGraphics();
        graphics.rotate(Math.toRadians(angle), 100, 100);
        graphics.drawImage(icon, 0, 0, 200, 200, null);
        icon = rotate;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.setFont(Commom.FONT_TITLE);
        // 绘制图标
        g.create().drawImage(icon, 15, 15, 14, 14, null);
        // 绘制标题
        g.drawString(this.title, 40, 25);
    }
}
